package com.eqdd.yiqidian.utils;

import android.content.Intent;

import com.eqdd.yiqidian.base.AppConstent;
import com.eqdd.yiqidian.base.AppManager;
import com.eqdd.yiqidian.base.BaseApplication;
import com.eqdd.yiqidian.bean.User;
import com.eqdd.yiqidian.ui.LoginActivity;

import java.util.HashSet;

import cn.jpush.android.api.JPushInterface;
import io.rong.imkit.RongIM;


/**
 * Created by lv on 17-9-9.
 */

public class LogoutUtil {
    public static void logout() {
        User user = GreenDaoUtil.getUser();
        HashSet<String> tags = new HashSet<>();
        tags.add(GreenDaoUtil.getUser().getCompanyId() + "_0");
        tags.add(user.getCompanyId() + "_" + user.getDepartId());
        tags.add(user.getCompanyId() + "__" + user.getPostId());
        JPushInterface.deleteAlias(BaseApplication.getApplication(), 0);
        JPushInterface.deleteTags(BaseApplication.getApplication(), 0, tags);
        GreenDaoUtil.deleteAllUser();
        GreenDaoUtil.clearPushCode();
        AppConstent.user = null;
//                                SPUtil.clearData();
        RongIM.getInstance().logout();
        AppManager.getAppManager().finishAllActivity();
        Intent intent = new Intent(BaseApplication.getApplication(), LoginActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        BaseApplication.getApplication().startActivity(intent);
    }
}
